package Java8.optional;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

@Fork(1)
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public class OrElseAndOrElseGetBenchmarkRunner {

    private OrElseAndOrElseGet orElsevsOrElseGet = new OrElseAndOrElseGet();

    public static void main(String[] args) throws RunnerException, IOException {
        //org.openjdk.jmh.Main.main(args);
        Options opt = new OptionsBuilder()
            .include(OrElseAndOrElseGetBenchmarkRunner.class.getSimpleName())
            .forks(1)
            .warmupIterations(1)
            .measurementIterations(5)
            .build();

        new Runner(opt).run();
    }

    @Benchmark
    public String orElseBenchmark() {
        return orElsevsOrElseGet.getNameUsingOrElse("baeldung");
    }

    @Benchmark
    public String orElseGetBenchmark() {
        return orElsevsOrElseGet.getNameUsingOrElseGet("baeldung");
    }

}
